import logging

from app.core.config import Settings
from app.core.logger_manager import AsyncSafeLogger, parse_log_level

settings = Settings()

logger_manager = AsyncSafeLogger(
    log_level=parse_log_level(settings.LOG_LEVEL),
    log_file=f"{settings.LOG_DIR}/app.log",  # 实际会生成 app-2024-06-02.log
    rotation_type="time",  # 启用按天轮转
    max_bytes=settings.LOG_MAX_BYTES,  # 10 MB
    backup_count=settings.LOG_BACKUP_COUNT,  # 保留最近7天日志
    console=settings.DEBUG,
    dependency_levels={
        lib_name: parse_log_level(level_str) for lib_name, level_str in settings.THIRD_PARTY_LOG_LEVELS.items()
    },
    console_formatter=logging.Formatter("%(asctime)s [%(levelname)s] - %(message)s", datefmt="%H:%M:%S"),
)


__all__ = ["settings", "logger_manager"]
